<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script src="/libs/react.development.js"></script>
    <script src="/libs/react-dom.development.js"></script>
    <script src="/libs/babel.min.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      class Weather extends React.Component {
        constructor(props) {
          super(props);
        }
        // 这里写state
        state = {
          isHot: true,
        };

        change = () => {
          // 不能直接改 state
          // this.state.isHot = !this.state.isHot;
          // 这样改
          this.setState({ isHot: !this.state.isHot });
        };
        render() {
          return (
            <h1 onClick={this.change}>
              今天天气很{this.state.isHot ? "炎热" : "凉爽"}
            </h1>
          );
        }
      }
      ReactDOM.render(<Weather />, document.getElementById("root"));
    </script>
  </body>
</html>
